Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new resource opsgenie_team_membership, refs #65 #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arnisoph
Copy link
Contributor

Signed-off-by: Arnold Bechtoldt [email protected]

@arnisoph
Copy link
Contributor Author

old one somehow became dirty #156

return &schema.Resource{
Create: resourceOpsGenieTeamMembershipCreate,
Read: handleNonExistentResource(resourceOpsGenieTeamMembershipRead),
//Update: resourceOpsGenieTeamMembershipUpdate, // requires https://github.com/opsgenie/opsgenie-go-sdk-v2/issues/59
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr looks good i'll talk with the internal team about go-sdk-v2 membership update status
Thank you @arnisoph

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have update support. if we introduce this users cannot change roles in their teams. I'll create a internal ticket and let you know.

maybe we can use update function to
-> get team -> update our user role -> update team flow
This way we can update our team members ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even plan to implement it, it's just a comment :D

@arnisoph arnisoph force-pushed the team_membership-resource2 branch from 1b3b3bd to dbb5597 Compare August 20, 2020 14:16
@arnisoph
Copy link
Contributor Author

any necessary changes pending?

@arnisoph
Copy link
Contributor Author

@ffahri any pending changes required in this PR?

@ffahri
Copy link

ffahri commented Sep 4, 2020

@arnisoph yes for update members please use team api it takes patch and we can pass the member inside that request

Copy link

@ffahri ffahri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use team api to update members (api supports)

@arnisoph
Copy link
Contributor Author

arnisoph commented Sep 4, 2020

???

@ffahri
Copy link

ffahri commented Sep 4, 2020

@arnisoph
Copy link
Contributor Author

arnisoph commented Sep 4, 2020

You need the full member list for this. I don't see how we can use this for opsgenie_team_membership

@arnisoph
Copy link
Contributor Author

@ffahri 👋 :D

@ffahri
Copy link

ffahri commented Sep 23, 2020

You dont need the full member list for that as you can see endpoint is supported in PATCH operations so you just need to send changed user is enough

@arnisoph arnisoph force-pushed the team_membership-resource2 branch from dbb5597 to ac29d0d Compare October 19, 2020 06:52
@arnisoph
Copy link
Contributor Author

arnisoph commented Oct 19, 2020

@ffahri sorry I still don't understand. Can you please show me how a PATCH request would look like when removing a member from a team?

I don't even understand this broken sentence in the docs:

This request changes team members to given list above. In other words, It is not append them as new members.

To which list does the first sentence refer?

Why can't we merge the current PR which is just working and meets the requirements of the initial feature request? We can still make it perfect afterwards if really necessary...

@jbeemster
Copy link

Hi all - sorry to revive a long dead PR - this is a feature we have wanted for some time as we cannot effectively manage team membership via Terraform for OpsGenie without segmenting out membership from the team creation.

Is there any chance of this PR being dusted of and merged or would I better off taking this PR as inspiration and submitting a new one?

@jbeemster
Copy link

jbeemster commented Jun 8, 2022

As an update have solved this with the mastercard/restapi provider with the following configuration if anyone else needs a more formal solution for this.

provider "restapi" {
  alias = "opsgenie"

  uri = "https://api.opsgenie.com"

  create_method         = "POST"
  update_method         = "POST"
  read_method           = "GET"
  create_returns_object = true
  write_returns_object  = true
  destroy_method        = "DELETE"

  headers = {
    "Content-Type"  = "application/json",
    "Authorization" = "GenieKey ${var.opsgenie_api_key}"
  }

  timeout = 15
}

resource "restapi_object" "opsgenie_team_membership" {
  for_each = toset(local.team_ids)

  path = "/v2/teams/${each.value}/members"

  data = jsonencode({
    user = {
      id = opsgenie_user.user.id
    },
    role = "user"
  })

  object_id = sha256("${opsgenie_user.user.id}-${each.value}")

  create_method  = "POST"
  create_path    = "/v2/teams/${each.value}/members"
  update_method  = "POST"
  update_path    = "/v2/teams/${each.value}/members"
  read_method    = "GET"
  read_path      = "/v2/teams/${each.value}"
  destroy_method = "DELETE"
  destroy_path   = "/v2/teams/${each.value}/members/${opsgenie_user.user.id}"
}

One major drawback still is that it is impossible with this provider to assert that the user is attached to the team as there is no GET request for an individual membership to the team - so its needed instead to parse out the teams API member list and check for existence in there.

Its possible to check for in a bit of a difficult way like so with TF v1.2.x:

locals {
  # Extract team membership maps from api_response
  team_members = { for k, v in restapi_object.opsgenie_team_membership : k => { for x in jsondecode(v.api_response)["data"]["members"] : x["user"]["id"] => x } }
  # Verify that user is a member of all teams
  team_membership_checks = alltrue([for k, v in local.team_members : lookup(v, opsgenie_user.user.id, "") != ""])
}

output "opsgenie_user_membership_check" {
  value = local.team_membership_checks

  precondition {
    condition     = local.team_membership_checks
    error_message = "The user must be attached to all OpsGenie teams they are assigned to - please remove 'module.opsgenie_user[0].restapi_object.opsgenie_team_membership[<team_name>]' and re-apply."
  }
}

@MarcosRava
Copy link

please, someone could merge this feature? Its very important to manage team members changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants